package com.base.taskreports.reports.service.impl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.base.taskreports.reports.dao.jfu.TblCqpntPointOutFlowDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.taskreports.common.utlis.DateUtil;
import com.base.taskreports.common.utlis.TableNameUtil;
import com.base.taskreports.reports.dao.jfs.TblCqpntPointInFlowDao;
import com.base.taskreports.reports.entiyt.jfs.TblCqpntPointInFlowEntity;
import com.base.taskreports.reports.entiyt.jfs.TblPointActivityEntity;
import com.base.taskreports.reports.service.TblCqpntPointInFlowService;

import net.sf.jsqlparser.expression.StringValue;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张玉涛
 * @since 2021-11-09
 */
@DS("jfs")
@Service("tblCqpntPointInFlowService")
public class TblCqpntPointInFlowServiceImpl extends ServiceImpl<TblCqpntPointInFlowDao, TblCqpntPointInFlowEntity> implements TblCqpntPointInFlowService {
    
	@Autowired(required=true)
	private TblCqpntPointInFlowDao tblCqpntPointInFlowDao;

	@Autowired(required=true)
	private TblCqpntPointOutFlowDao tblCqpntPointOutFlowDao;

	/**
	 * 积分-用分tbl_cqpnt_point_out_flow01 流水表
	 */
	public static final String JFYFLS = "tbl_cqpnt_other_buss_flow";
	
	 /**
     * 积分-送分表tbl_cqpnt_point_in_flow01
     */
    public static final String JFSF = "tbl_cqpnt_point_in_flow";


	//已失效积分金额浮动比率
	@Override
	public String selectFloatingRateExpiredPoints(String dateTime) {
		Map<String, String> dayUtlis = TableNameUtil.dayUtlis(dateTime,JFYFLS);

		//昨天 已失效积分金额
		Integer currencyPoints  = tblCqpntPointInFlowDao.countRateExpiredPoints(
				dayUtlis.get("jfsfzDayTabName"),
				dayUtlis.get("yestoyyyymmddday"),
				dayUtlis.get("floSt"),
				dayUtlis.get("bussTp"));

		return currencyPoints!= null ?currencyPoints.toString() :"0";
	}

    
	//非货币积分发放金额浮动比率
	@DS("jfs")
	@Override
	public List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints(String DateTime) {
		// TODO Auto-generated method stub
		Map<String, String> dayUtlis = TableNameUtil.dayUtlis(DateTime,JFSF);
		//非货币积分发放金额
		List<TblCqpntPointInFlowEntity> tblCqpntPointInFlowList =  tblCqpntPointInFlowDao.selectFloatingRateOfNonMonetaryPoints(
				dayUtlis.get("jfsfzDayTabName"),
				dayUtlis.get("assignjfsfqDayTabName"),
				dayUtlis.get("yestoyyyymmddday"),
				dayUtlis.get("assignYestoyyyymmddday"),
				dayUtlis.get("pointTp"),
				dayUtlis.get("floSt"));
		return tblCqpntPointInFlowList;
	}
	 // 非人民币货币积分发放金额浮动比率
	@DS("jfs")
	@Override
	public List<TblCqpntPointInFlowEntity> selectFloatingRatioOfNonRMBCurrencyPoints(String DateTime, List<TblPointActivityEntity> tblPointActivityList) {
		   // TODO Auto-generated method stub
		Map<String, String> dayUtlis = TableNameUtil.dayUtlis(DateTime,JFSF);
		
		//昨天 非人民币货币积分发放金额
		Integer currencyPoints  = tblCqpntPointInFlowDao.selectCurrencyPoints(
				dayUtlis.get("jfsfzDayTabName"),
				dayUtlis.get("yestoyyyymmddday"),
				dayUtlis.get("floSt"),tblPointActivityList);
		
		List<TblCqpntPointInFlowEntity> tblCqpntPointInFlowList = new ArrayList<TblCqpntPointInFlowEntity>();
		TblCqpntPointInFlowEntity tblCqpntPointInFlowEntity = new TblCqpntPointInFlowEntity();
		tblCqpntPointInFlowEntity.setToday(currencyPoints.longValue());
		tblCqpntPointInFlowList.add(tblCqpntPointInFlowEntity);
		return tblCqpntPointInFlowList;
	}
	// 事后结算积分发放金额浮动比率
	@DS("jfs")
	@Override
	public List<TblCqpntPointInFlowEntity> selectFloatingRatioOfBonusAmountIssuedAfterSettlement(String DateTime,List<TblPointActivityEntity> tblPointActivityList) {
		// TODO Auto-generated method stub
		
          Map<String, String> dayUtlis = TableNameUtil.dayUtlis(DateTime,JFSF);
		//昨天 事后结算积分发放金额
          Integer currencyPoints  = tblCqpntPointInFlowDao.selectCurrencyPoints(
				dayUtlis.get("jfsfzDayTabName"),
				dayUtlis.get("yestoyyyymmddday"),
				dayUtlis.get("floSt"),tblPointActivityList);
		
		List<TblCqpntPointInFlowEntity> tblCqpntPointInFlowList = new ArrayList<TblCqpntPointInFlowEntity>();
		TblCqpntPointInFlowEntity tblCqpntPointInFlowEntity = new TblCqpntPointInFlowEntity();
		tblCqpntPointInFlowEntity.setToday(currencyPoints.longValue());
		//tblCqpntPointInFlowEntity.setRemark(remark);
		tblCqpntPointInFlowList.add(tblCqpntPointInFlowEntity);
		return tblCqpntPointInFlowList;
		
	}
	// 单用户货币积分余额
	@DS("jfs")
	@Override
	public List<TblCqpntPointInFlowEntity> selectSingleUserCurrencyScoreBalanceNFloatingRatio(String DateTime) {
		// TODO Auto-generated method stub
		 Map<String, String> dayUtlis = TableNameUtil.dayUtlis(DateTime,JFSF);
		List<TblCqpntPointInFlowEntity> tblCqpntPointInFlowList =  tblCqpntPointInFlowDao.selectSingleUserCurrencyScoreBalanceNFloatingRatio(
				dayUtlis.get("jfsfzDayTabName"),
				dayUtlis.get("yestoyyyymmddday"),
				dayUtlis.get("pointTpOne"),
				dayUtlis.get("floSt"));
		return tblCqpntPointInFlowList;
	}
	// 单用户非货币积分余额
	@DS("jfs")
	@Override
	public List<TblCqpntPointInFlowEntity> selectSingleUserNonCurrencyPointsBalanceNFloatingRatio(String DateTime) {
		// TODO Auto-generated method stub
		   Map<String, String> dayUtlis = TableNameUtil.dayUtlis(DateTime,JFSF);
			List<TblCqpntPointInFlowEntity> tblCqpntPointInFlowList =  tblCqpntPointInFlowDao.selectSingleUserCurrencyScoreBalanceNFloatingRatio(
					dayUtlis.get("jfsfzDayTabName"),
					dayUtlis.get("yestoyyyymmddday"),
					dayUtlis.get("pointTp"),
					dayUtlis.get("floSt"));
	     return tblCqpntPointInFlowList;
	}
	// 临时用户（非注册用户,即不使用userID用户）交易数量浮动比
	@DS("jfs")
	@Override
	public List<TblCqpntPointInFlowEntity> selectFloatingRatioOfTheNumberOfTransactionsByTemporaryUsers(String DateTime) {
		// TODO Auto-generated method stub
		Map<String, String> dayUtlis = TableNameUtil.dayUtlis(DateTime,JFSF);
		//交易数量
		Integer theNumberOfTransactions = tblCqpntPointInFlowDao.countTheNumberOfTransactions(dayUtlis.get("jfsfzDayTabName"),dayUtlis.get("yestoyyyymmddday"),dayUtlis.get("floSt"));
		List<TblCqpntPointInFlowEntity> list = new ArrayList<TblCqpntPointInFlowEntity>();
		TblCqpntPointInFlowEntity tblCqpntPointInFlowEntity = new TblCqpntPointInFlowEntity();
		tblCqpntPointInFlowEntity.setToday(theNumberOfTransactions.longValue());
		list.add(tblCqpntPointInFlowEntity);
		return list;
	}
	// 积分余额为负数量			
	@DS("jfs")
	@Override
	public List<TblCqpntPointInFlowEntity> selectTheCreditBalanceNegativeQuantity(String DateTime) {
		// TODO Auto-generated method stub
		List<TblCqpntPointInFlowEntity> tblCqpntPointInFlowList =  tblCqpntPointInFlowDao.selectTheCreditBalanceNegativeQuantity();
		return tblCqpntPointInFlowList;
	}

}
